package demo.practice.leetcode_eveyday;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class P220 {

    public static void main(String[] args) {
        P220 p220= new P220();

        p220.containsNearbyAlmostDuplicate(new int[]{-2147483648,2147483647},1,1);
    }

    public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
            //使得 abs(nums[i] - nums[j]) <= t ，同时又满足 abs(i - j) <= k

        List<Integer> list= new ArrayList<>();
        for(int i=0;i<nums.length;i++){
            list.add(i);
        }

        Collections.sort(list,(i,i2)->nums[i]-nums[i2]);

        for(int i=0;i<list.size();i++){
            for (int j=i+1;j<list.size();j++){
                if(Math.abs((long)nums[ list.get(i)]-(long)nums[list.get(j)])>t)
                    break;

                if(Math.abs(list.get(i)-list.get(j))<=k )
                    return true;
            }
        }
        return false;
    }




}
